package com.web.zsqqimengzhixing.service.impl;

import com.web.zsqqimengzhixing.mapper.ArticlesMapper;
import com.web.zsqqimengzhixing.pojo.Articles;
import com.web.zsqqimengzhixing.pojo.Comments;
import com.web.zsqqimengzhixing.pojo.Upvotes;
import com.web.zsqqimengzhixing.service.ArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ArticlesServiceImpl implements ArticlesService {
    @Autowired
    private ArticlesMapper articlesMapper;

    /**
     * 查找全部文章
     * @return
     */
    @Override
    public List<Articles> select() {
        List<Articles> articles = articlesMapper.select();
        System.out.println(articles);
        return articles;
    }

    /**
     * 添加文章
     * @param articles
     */
    @Override
    public void addart(Articles articles) {
        articles.setPublishTime(LocalDateTime.now());
        articlesMapper.insert(articles);
    }

    /**
     * 添加评论
     * @param comments
     */
    @Override
    public void addcom(Comments comments) {
        comments.setCommentTime(LocalDateTime.now());
        articlesMapper.insertcom(comments);
    }

    /**
     * 查询评论
     *
     * @param articleId
     * @return
     */
    @Override
    public List<Comments> selectcom(Integer articleId) {
        return articlesMapper.selectcom(articleId);
    }
    /**
     * 点赞
     * @param
     */
    @Override
    public void upvotes(Upvotes upvotes) {
        upvotes.setUpTime(LocalDateTime.now());
        articlesMapper.upvotes(upvotes);
    }
    /**
     * 查询点赞
     * @param articleId
     * @return
     */
    @Override
    public List<Upvotes> selectupvotes(Integer articleId) {
        return articlesMapper.selectupvotes(articleId);
    }


}
